LRU = require("lru-cache")

g_lru = []

exports.common_lrucache =
  load: (id, cb) ->
    for [timeout,cache] in g_lru
      v = cache.get(id)
      if v
        return cb null,v
    return cb null,null    
  save: (id,val,timeout,cb) ->
    if timeout < 10
      return cb null,val
    c = null
    for [timeout2,cache] in g_lru
      if timeout == timeout2
        c = cache
        break
    if c == null
      c = LRU {max:100, maxAge:timeout*1000}
      g_lru.push [timeout,c]
    c.set(id,val)
    return cb null,val

